package com.campus.bbs;

import java.io.IOException;
import java.net.MalformedURLException;
import java.util.ArrayList;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.campus.utils.Http;

public class T implements GetITieInfo {

	/**
	 * @param args
	 * @throws IOException
	 * @throws MalformedURLException
	 */
	public static void main(String[] args) throws MalformedURLException,
			IOException {
		// TODO Auto-generated method stub
             ArrayList<TieInfo>list=new ArrayList();
             
		String url = "http://tieba.baidu.com/f?kw=cqupt";
		// url="http://tieba.baidu.com/mo/q---180EEE5213CE8AE5CA43FD038A45F50D%3AFG%3D1--1-3-0--2--wapp_1463661073517_477/m?kw=%E9%87%8D%E5%BA%86%E9%82%AE%E7%94%B5%E5%A4%A7%E5%AD%A6&lp=1030";

		String resp = Http.get(url, "UTF-8");
		Document doc = Jsoup.parse(resp);
		// Jsoup.parse("&nbsp;").text(), " ")
		Elements ele = doc.select("div.threadlist_title.pull_left.j_th_tit");
		ele = doc.select("div.t_con.cleafix");
		for (Element e : ele) {
			TieInfo info=new TieInfo();
			String time=(e.select("span.threadlist_reply_date.pull_right.j_reply_data").text());
			// System.out.println(e.select("a").text().replace(Jsoup.parse("&nbsp;").text(),
			// " "));
			String last=e.select("span.tb_icon_author_rely.j_replyer").text();
			for (Element urle : e.select("a")) {
				//System.out.println("1" + urle.text() + "2");

			}
			String author=e.select("span.tb_icon_author").attr("title");
//			System.out
//					.println(e
//							.select("soan.threadlist_reply_date.pull_right.j_reply_data"));
			String urlp=(e.select("a").attr("href"));
			// System.out.println(e.select("p").text());
			
			
			info.firstname=author;
			info.lastname=last;
			info.url=urlp;
			info.time=time;
			info.sum=e.select("span.threadlist_rep_num.center_text").text();
			info.title=e.select("a.j_th_tit").text();
			list.add(info);
			//System.out.println("author"+author);
			//System.out.println("urlp"+urlp);
			//System.out.println("time"+time);
			//System.out.println("last"+last);
			//System.out.println("title"+e.select("a.j_th_tit").text());
			//System.out.println(e.select("span.threadlist_rep_num.center_text").text());
			
		}
	}

	public ArrayList<TieInfo> getTieInfoList() throws MalformedURLException, IOException  {
		// TODO Auto-generated method stub
		   ArrayList<TieInfo>list=new ArrayList();
           
			String url = "http://tieba.baidu.com/f?kw=cqupt";
			// url="http://tieba.baidu.com/mo/q---180EEE5213CE8AE5CA43FD038A45F50D%3AFG%3D1--1-3-0--2--wapp_1463661073517_477/m?kw=%E9%87%8D%E5%BA%86%E9%82%AE%E7%94%B5%E5%A4%A7%E5%AD%A6&lp=1030";

			String resp = Http.get(url, "UTF-8");
			Document doc = Jsoup.parse(resp);
			// Jsoup.parse("&nbsp;").text(), " ")
			Elements ele = doc.select("div.threadlist_title.pull_left.j_th_tit");
			ele = doc.select("div.t_con.cleafix");
			for (Element e : ele) {
				TieInfo info=new TieInfo();
				String time=(e.select("span.threadlist_reply_date.pull_right.j_reply_data").text());
				// System.out.println(e.select("a").text().replace(Jsoup.parse("&nbsp;").text(),
				// " "));
				String last=e.select("span.tb_icon_author_rely.j_replyer").text();
				for (Element urle : e.select("a")) {
					//System.out.println("1" + urle.text() + "2");

				}
				String author=e.select("span.tb_icon_author").attr("title");
//				System.out
//						.println(e
//								.select("soan.threadlist_reply_date.pull_right.j_reply_data"));
				String urlp=(e.select("a").attr("href"));
				// System.out.println(e.select("p").text());
				
				
				info.firstname=author;
				info.lastname=last;
				info.url=urlp;
				info.time=time;
				info.sum=e.select("span.threadlist_rep_num.center_text").text();
				info.title=e.select("a.j_th_tit").text();
				list.add(info);
				
	}
			return list;
	}

}
